---
title: Create/select legal case context
summary: Establishes the active legal case for a manager instance, either by locating an existing case for the current claim or creating a new one, then enforces claim-visibility authorization.
status: draft
owner: SAIF Documentation Pipeline
last_reviewed: 2026-08-21
library: SAIF.Application.Claim.Legal
reference_type: embedded
operation_id: OP-LGL-001
trigger: Web tier sets a context/claim number, or requests a new case
---

# Create select legal case context

This operation establishes the `CurrentCase` (`clsLegalCase`) and its header (`clsLegalData`) for a `SAIF.Application.Claim.Legal` manager instance, either by finding an existing legal case for the active claim or by creating a new one, and then gates exposure of that data behind claim-level authorization checks.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-LGL-001 |
| **Trigger** | Web tier sets a context/claim number, or requests a new case |
| **Inputs** | `ContextNumber`/claim ID, `SecurityPrincipal` |
| **Outputs** | `CurrentCase` (`clsLegalCase`), case header (`clsLegalData`), `m_CanViewClaim`/`Message` |
| **Primary components** | `LegalManagerBase.CreateCase` / `LegalManagerBase.SetCurrentCase` / `LegalManagerBase.OnContextChanged` |
| **Entry point** | `SAIF.Application.Claim.Legal\LegalManagerBase.vb` |

## Steps

1. Web tier sets a claim/case context number (`ContextNumber`) or claim ID.
2. `OnContextChanged()` looks up matching cases for the current claim.
   - `clsFindCase.GetCases(DPI, criteria)` retrieves the candidate case list.

     > **Origin**: delegates to `SAIF.Business.Claim.Legal` (see [operations and processes](../../saif-business-claim-legal/operations-processes.md)) — the internal step sequence of `clsFindCase.GetCases` was not traced in this run's Stage 1 analysis; this callout is inferred/best-effort pointing to the expected sibling library operation page.*
   - If a matching case is found: call `SetClaimContext`.

     > **Origin**: delegates to `SAIF.Application.Claim` (see [operations and processes](../../saif-application-claim/operations-processes.md)) — `ClaimAppManager.SetClaimContext`'s own step sequence was not traced in this run's Stage 1 analysis; this callout is inferred/best-effort.*
   - Then call `SetCurrentCase(caseID)` (step 3).
3. `SetCurrentCase(caseID)` loads the case data:
   - `clsLegalCase.GetLegalCase(DPI, caseID)` retrieves the full legal-case business object.

     > **Origin**: delegates to `SAIF.Business.Claim.Legal` (see [operations and processes](../../saif-business-claim-legal/operations-processes.md)) — inferred/best-effort pointer; step sequence not traced in this run.*
   - A `clsLegalData` header object is loaded via the stored procedure `pk80001_legalNet.getHeader` ([SQL-012](../sql/SQL-012-get-legal-case-header.md)), executed through `SqlHelper.ResultSetQuery` with a REF CURSOR output parameter.
4. On the new-case path, `CreateCase()` instead:
   - Creates `clsLegalCase.NewLegalCase(DPI)`.

     > **Origin**: delegates to `SAIF.Business.Claim.Legal` (see [operations and processes](../../saif-business-claim-legal/operations-processes.md)) — inferred/best-effort pointer; step sequence not traced in this run.*
   - Copies the claim-level attorney-firm assignment (`ClaimData.LegalRepProviderLocSeqNum`/`LegalRepParentProvLocSeqNum`) onto the new case.
   - Loads the same `clsLegalData` header ([SQL-012](../sql/SQL-012-get-legal-case-header.md)).
5. `LegalManagerBase.OnRetrieve()` enforces claim-visibility authorization before the case data is exposed to the caller:
   - Admin-group bypass: users in the Legal admin group may view any claim ([BR-LGL-001](../business-rules.md#br-lgl-001-admin-group-bypasses-claim-conflict-and-exposure-checks)).
   - If not admin: a worker-conflict claim requires both conflict and exposure access, unless a security override is present ([BR-LGL-002](../business-rules.md#br-lgl-002-worker-conflict-claims-require-conflict-and-exposure-access)).
   - If not admin: an exposure-flagged claim requires exposure access, unless a security override is present ([BR-LGL-003](../business-rules.md#br-lgl-003-exposure-flagged-claims-require-exposure-access)).
   - On failure of either check: `m_CanViewClaim = False` and `Message = ClaimAppConstants.ERRORCONFIDENTIALCLAIM`.
   - On success: `m_CanViewClaim = True` and any prior message is cleared.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Context/claim number set]) --> Changed[OnContextChanged]
	Changed --> Found{Matching case found?}
	Found -->|Yes| SetCtx[SetClaimContext + SetCurrentCase]
	Found -->|No, new case| Create[CreateCase: NewLegalCase]
	SetCtx --> LoadHeader[Load clsLegalData header<br>via getHeader stored procedure]
	Create --> CopyAtty[Copy claim attorney-firm assignment]
	CopyAtty --> LoadHeader
	LoadHeader --> Retrieve[OnRetrieve authorization gate]
	Retrieve --> Admin{Admin group?}
	Admin -->|Yes| Allowed([m_CanViewClaim = True])
	Admin -->|No| Checks{Conflict/exposure<br>access satisfied?}
	Checks -->|Yes| Allowed
	Checks -->|No| Denied([m_CanViewClaim = False<br>ERRORCONFIDENTIALCLAIM])
```

## Failure and edge-case behavior

- No matching case found and no new-case request: the manager has no `CurrentCase`, and dependent screen operations are unavailable until a context is established.
- Claim-visibility check fails: `m_CanViewClaim = False`, `Message = ClaimAppConstants.ERRORCONFIDENTIALCLAIM`, and the case data remains loaded internally but is not exposed to the caller.

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

## Sources
- `SAIF.Application.Claim.Legal\LegalManagerBase.vb`
- `SAIF.Application.Claim.Legal\clsLegalData.vb`
